from fastapi.responses import JSONResponse
from pydantic import conint

from common.base.base_routers import get_custom_router
from services.services_module.api import ServicesModuleApi
from services.services_module.schemas.configs import LteConfig, GsmConfig
from settings import settings

sm_api = ServicesModuleApi()
services_module_router = get_custom_router(sm_api, prefix='/services_module', tags=['services_module'])


@services_module_router.post('/set-lte-config/', response_class=JSONResponse)
async def set_lte_config(index: conint(ge=0, lt=settings.SERVICES_MODULE_NUMBER), config: LteConfig):
    return await sm_api.set_lte_config(index, config)


@services_module_router.post('/set-gsm-config/', response_class=JSONResponse)
async def set_gsm_config(index: conint(ge=0, lt=settings.SERVICES_MODULE_NUMBER), config: GsmConfig):
    return await sm_api.set_gsm_config(index, config)


@services_module_router.get('/get-all-lte-configs/', response_class=JSONResponse)
async def get_all_lte_configs():
    return await sm_api.get_all_lte_configs()


@services_module_router.get('/get-lte-config/', response_class=JSONResponse)
async def get_lte_config(index: conint(ge=0, lt=settings.SERVICES_MODULE_NUMBER)):
    return await sm_api.get_lte_config(index)


@services_module_router.get('/get-all-gsm-configs/', response_class=JSONResponse)
async def get_all_gsm_configs():
    return await sm_api.get_all_gsm_configs()


@services_module_router.get('/get-gsm-config/', response_class=JSONResponse)
async def get_gsm_config(index: conint(ge=0, lt=settings.SERVICES_MODULE_NUMBER)):
    return await sm_api.get_gsm_config(index)


@services_module_router.get('/get-all-module-types/', response_class=JSONResponse)
async def get_all_module_types():
    return await sm_api.get_all_module_types()


@services_module_router.get('/get-module-type/', response_class=JSONResponse)
async def get_module_type(index: conint(ge=0, lt=settings.SERVICES_MODULE_NUMBER)):
    return await sm_api.get_module_type(index)


@services_module_router.get('/get-all-telemetry/', response_class=JSONResponse)
async def get_all_telemetry():
    return await sm_api.get_all_telemetry()


@services_module_router.get('/get-telemetry/', response_class=JSONResponse)
async def get_telemetry(index: conint(ge=0, lt=settings.SERVICES_MODULE_NUMBER)):
    return await sm_api.get_telemetry(index)
